package main;


public class Biletomat {
	private static Biletomat biletomat = null;
	private long ileWBiletomacie = 0;
	private stanBiletomatu state = stanBiletomatu.INIT;
	
	
	private Biletomat() {
	}
	
	public static Biletomat getInstance() {
		if(biletomat == null) {
			biletomat = new Biletomat();
		}
		return biletomat;
	}
	
	public double ileWBiletomacie() {
		return ileWBiletomacie;
	}
	
	public int ileDoZaplaty(Bilet b, Ulga u) {
		return b.podajCene() / u.podajUlge();
	}
	
	
	public double zaplac(Bilet b, Ulga u, double ileWplacono) {
		int ileDoZaplaty = ileDoZaplaty(b,u); 
		
		//wplacono za malo, zwracana jest kasa
		if(ileWplacono < ileDoZaplaty ) {
			System.out.println("Wplacono za malo.");
			return ileWplacono;
		}
		//nie ma reszty:
		if(ileWplacono - ileDoZaplaty > ileWBiletomacie) {
			return ileWplacono; 
		}
		//zwracana reszta
		ileWBiletomacie += ileDoZaplaty - ileWplacono;
		return ileWplacono - ileDoZaplaty;
	}
	
	
	
	 
	/*
	public static void main(String[] args) {
		Biletomat b = Biletomat.getInstance();
		
	}
*/	
	
	
}
